#include <catch2/catch.hpp>

#include <unordered_set>

#include "solution.hpp"

using namespace solution_018;

namespace
{


bool equal(std::vector<int> a, std::vector<int> b)
{
    if (a.size() != b.size())
        return false;
    for (int i = a.size() - 1; i >= 0; --i) {
        for (auto it = b.begin(); it != b.end(); ++it) {
            if (a[i] == *it) {
                b.erase(it);
                break;
            }
        }
        a.pop_back();
        if (a.size() != b.size())
            return false;
    }
    return true;
}

bool equal(std::vector<std::vector<int>> a, std::vector<std::vector<int>> b)
{
    if (a.size() != b.size())
        return false;
    for (int i = a.size() - 1; i >= 0; --i) {
        for (auto it = b.begin(); it != b.end(); ++it) {
            if (equal(a[i], *it)) {
                b.erase(it);
                break;
            }
        }
        a.pop_back();
        if (a.size() != b.size())
            return false;
    }
    return true;
}

}

TEST_CASE("18. 4Sum", "[018]") {

SECTION("example 1") {
    std::vector<int> arr{1,0,-1,0,-2,2};
    auto ans = Solution().fourSum(arr, 0);
    CAPTURE(ans);
    CHECK(equal(ans, std::vector< std::vector<int> >{{-1,0,0,1},{-2,-1,1,2},{-2,0,0,2}}));
}

}
